package com.github.mzule.fantasyslide.app;

import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.util.Base64;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;


import com.github.mzule.fantasyslide.util.CrashUtil;

import java.text.DecimalFormat;

/**
 * Created by zhou on 2019-01-30.
 */

public class InfoActivity extends BaseActivity {
   private ImageView info_avatar = null;
   private TextView info_name  = null;
    private TextView info_sex  = null;
    private TextView info_idCard  = null;
    private TextView info_workplace  = null;
    private TextView info_score  = null;
    private Button info_btn_Back = null;

    public void onCreate(Bundle savedInstanceState) {
        setContentView(R.layout.info);
        super.onCreate(savedInstanceState);
        CrashUtil crashUtil = CrashUtil.getInstance();
        crashUtil.init(this);
        if (!initeActivity())
        {
            this.finish();
            return;
        }
        Bundle bundle = getIntent().getExtras();
        String avatar ="data:image/jpeg;base64,"+bundle.getString("avatar");
        String name = bundle.getString("name");
        String sex = bundle.getString("sex");
        String idCard = bundle.getString("idCard");
        String workplace = bundle.getString("workplace");
        DecimalFormat df = new DecimalFormat("#.00");
        String score =df.format(Double.parseDouble(bundle.getString("score"))) +"%" ;

        //Log.e("avatar********", avatar);
        byte[] decodedString = Base64.decode(avatar, Base64.DEFAULT);

       // BitmapFactory.Options options = new BitmapFactory.Options();
 //options.inJustDecodeBounds = true;
 //不会加载，只会获取图片的一个尺寸
 //options里面储存了图片的高度和宽度
 //读取文件
       // BitmapFactory.decodeByteArray(decodedString, 0, decodedString.length,options);
 //改变图片的大小
 //double ratio = Math.max(options.outWidth *1.0d/1024f,options.outHeight *1.0d/1024);
 //options.inSampleSize =(int) Math.ceil(ratio);
 //设置后会加载图片
 //options.inJustDecodeBounds = false;
 //图片压缩完成
        Bitmap bitmap = BitmapFactory.decodeByteArray(decodedString, 0, decodedString.length);
        info_avatar.setImageBitmap(bitmap);
        info_name.setText("姓名："+name);
        info_sex.setText("性别："+sex);
        info_idCard.setText("身份证号："+idCard);
        info_workplace.setText("工作单位："+workplace);
        info_score.setText("相似度："+score);
    }

    private boolean initeActivity()
    {
        findViews();
        setListeners();
        return true;
    }
    private void findViews()
    {
        info_avatar = (ImageView) findViewById(R.id.info_avatar);
         info_name  = (TextView)findViewById(R.id.info_name);
          info_sex  = (TextView)findViewById(R.id.info_sex);
          info_idCard  = (TextView)findViewById(R.id.info_idCard);
          info_workplace  = (TextView)findViewById(R.id.info_workplace);
          info_score  = (TextView)findViewById(R.id.info_score);
        info_btn_Back = (Button)findViewById(R.id.info_btn_Back);
    }
    private void setListeners()
    {
        info_btn_Back.setOnClickListener(info_Back_Listener);
    }
    private Button.OnClickListener info_Back_Listener = new View.OnClickListener()
    {
        public void onClick(View v)
        {
            finish();
        }

    };
}
